package org.folio.rest.tools.utils;

import java.util.LinkedHashMap;
import java.util.Map;

public class LRUCache<K, V> extends LinkedHashMap<K, V> {
  private int size;

  private LRUCache(int size) {
      super(size, 0.75f, false); //false = use insertion order to evict
      this.size = size;
  }

  @Override
  protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
      return size() > size;
  }

  public static <K, V> LRUCache<K, V> newInstance(int size) {
      return new LRUCache<K, V>(size);
  }

}
